package org.xlx.xlx_oa.meet.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xlx.xlx_oa.common.BusinessException;
import org.xlx.xlx_oa.common.PageVo;
import org.xlx.xlx_oa.common.ResponseBean;
import org.xlx.xlx_oa.meet.api.MeetApplyApi;
import org.xlx.xlx_oa.meet.domain.dto.MeetApplyDto;
import org.xlx.xlx_oa.meet.domain.dto.MeetRoomArrangeDto;
import org.xlx.xlx_oa.meet.domain.vo.MeetApplyVo;
import org.xlx.xlx_oa.meet.service.MeetApplyService;
import org.xlx.xlx_oa.role_user.domain.dto.AdmProcessDto;
import org.xlx.xlx_oa.role_user.domain.vo.AuditVo;

import java.util.List;

@RestController
@RequestMapping("/v1/meet-apply")
public class MeetApplyController implements MeetApplyApi {
    @Autowired
    private MeetApplyService meetApplyService;

    @PostMapping("/saveApply")
    @Override
    public ResponseBean saveAttendanceApply(MeetApplyVo applyVo) {
        try {
            return ResponseBean.successFactory(meetApplyService.saveMeetApply(applyVo));
        } catch (BusinessException e) {
            return ResponseBean.failureFactory(e.getCode(), e.getMessage());
        } catch (Exception e) {
            return ResponseBean.failureFactory(e.getMessage());
        }
    }

    @PostMapping("/audit")
    @Override
    public ResponseBean<Boolean> auditApply(@RequestBody AuditVo auditVo) {
        return ResponseBean.successFactory(meetApplyService.auditMeetApply(auditVo));
    }

    @PostMapping("/beAuditList")
    @Override
    public ResponseBean<List<MeetApplyDto>> getBeAuditPage(@RequestBody PageVo pageVo) {
        List<MeetApplyDto> beAuditList = meetApplyService.getBeAuditList(pageVo);
        return ResponseBean.successFactory(beAuditList);
    }

    @PostMapping("/appliedList")
    @Override
    public ResponseBean<List<MeetApplyDto>> getAppliedPage(@RequestBody MeetApplyVo applyVo) {
        List<MeetApplyDto> applyList = meetApplyService.getApplyList(applyVo);
        return ResponseBean.successFactory(applyList);
    }

    @GetMapping("/detail/{applyId}")
    @Override
    public ResponseBean<List<AdmProcessDto>> getApplyDetail(@PathVariable(value = "applyId") Long applyId) {
        List<AdmProcessDto> applyDetail = meetApplyService.getApplyDetail(applyId);
        return ResponseBean.successFactory(applyDetail);
    }

    @GetMapping("/arrange/{roomId}")
    @Override
    public ResponseBean<List<MeetRoomArrangeDto>> getRoomArrange(@PathVariable(value = "roomId") Long roomId) {
        List<MeetRoomArrangeDto> arrangeDtos = meetApplyService.getMeetRoomArrange(roomId);
        return ResponseBean.successFactory(arrangeDtos);
    }
}

